import instance from "@/request/request";
import type { Res } from '@/request/ResultApi';

//获取所有订单项
export const getAllOrderItem = (size: number, current: number, orderId: number,
    productId:number,orderItemId:number,orderState:number): Res<null> =>{
    let srt=""
    if(productId!=-1)srt+="&productId="+productId
    if(orderItemId!=-1)srt+="&orderItemId="+orderItemId
    if(orderState!=-1)srt+="&orderState="+orderState
   return instance.post(`/orderItem/all?size=${size}&current=${current}&orderId=${orderId}${srt}`);
}
    

//添加订单项
export const addOrderItem = (data: {
    productId: String,
    orderId: number,
    num: number
}): Res<null> => instance.post("/orderItem/add", data);

//修改订单项
export const updateOrderItem = (data: {
    orderItemId: String,
    productId: String,
    orderId: number,
    state: String,
    num: number
}): Res<null> => instance.post("/orderItem/update", data);

//删除订单项
export const removeOrderItem = (orderItemId: number): Res<null> =>
    instance.post(`/orderItem/delete?orderItemId=${orderItemId}`);

//批量删除订单项
export const removeOrderItems = (data: []): Res<null> => instance.post("/orderItem/deletes", data);